import http from './http/index'
// import config from './config'
// const { apiUrl } = config

export const importMenus = new class {
  apis = ['menu.Import']
  fn = (page, menuFile) => {
    return http.upload(page, [{
      service: this.apis[0]
    }], {
      file: menuFile
    })
  }
}()

export const exportMenus = new class {
  apis = ['menu.Export']
  fn = () => {
    return http.url(this.apis[0])
    // const query = JSON.stringify([{
    //   service: this.apis[0]
    // }])
    // return apiUrl + '?' + query
    // return apiUrl + '?[{service: "' + this.apis[0] + '"}]'
  }
}()

export const updateMenuOrder = new class {
  apis = ['menu.UpdateMenuOrders']
  fn = (page, newOrders) => {
    return http.post(page, [{
      service: this.apis[0],
      args: {
        orders: newOrders
      }
    }])
  }
}()

export const deleteMenu = new class {
  apis = ['menu.DeleteMenu']
  fn = (page, id) => {
    return http.post(page, [{
      service: this.apis[0],
      args: {
        id: id
      }
    }])
  }
}()

export const updateMenu = new class {
  apis = ['menu.UpdateMenu']
  fn = (page, {
    id,
    alwaysShow,
    redirect,
    path,
    title,
    icon,
    noCache,
    affix,
    breadcrumb,
    activeMenu
  }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: {
        id,
        alwaysShow,
        redirect,
        path,
        title,
        icon,
        noCache,
        affix,
        breadcrumb,
        activeMenu
      }
    }])
  }
}()

export const addMenu = new class {
  apis = ['menu.AddMenu']
  fn = (page, {
    parentId,
    component,
    alwaysShow,
    redirect,
    path,
    title,
    icon,
    noCache,
    affix,
    breadcrumb,
    activeMenu
  }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: {
        parentId,
        component,
        alwaysShow,
        redirect,
        path,
        title,
        icon,
        noCache,
        affix,
        breadcrumb,
        activeMenu
      }
    }])
  }
}()

// const apiAddEmptyMenu = 'funcs.AddEmptyMenu'
// export const addEmptyMenu = {
//   apis: [apiAddEmptyMenu],
//   fn(info) {
//     // info['parentId'] = parentId
//     return http.post([{
//       service: apiAddEmptyMenu,
//       args: info
//     }], true)
//   }
// }

// const apiUpdateEmptyMenu = 'funcs.UpdateEmptyMenu'
// export const updateEmptyMenu = {
//   apis: [apiUpdateEmptyMenu],
//   fn({ id, path, title, icon }) {
//     return http.post([{
//       service: apiUpdateEmptyMenu,
//       args: {
//         id, path, title, icon
//       }
//     }], true)
//   }
// }

export const getMenuTree = new class {
  apis = ['menu.GetMenuTree']
  fn = (page) => {
    return http.post(page, [{
      service: this.apis[0]
    }])
  }
}()

export const listFuncs = new class {
  apis = ['menu.ListPages']
  fn = (page) => {
    return http.post(page, [{
      service: this.apis[0]
    }])
  }
}()

export const updateFuncs = new class {
  apis = ['menu.UpdatePages']
  fn = (page, pages) => {
    return http.post(page, [{
      service: this.apis[0],
      args: {
        pages: pages
      }
    }])
  }
}()
